<template>
  <div>
    <el-main>
      <el-table
        ref="table"
        :data="tableData"
        :border="true"
        style="width: 100%"
        size="small"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          prop="type"
          label="类型"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="integral"
          label="积分"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="email"
          label="邮箱"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="createTime"
          label="发生时间"
          :formatter="datetimeFormatter"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
    </el-main>
  </div>
</template>

<script>
import {searchIntegral} from "@/api/member/integral";
import {Status} from "@/utils/constant/status";
import {parseTime} from "@/utils/common";
import {ApiError} from "@/utils/errors";

export default {
  data() {
    return {
      Status,
      memberId: null,
      tableData: []
    }
  },
  created() {
    this.memberId = this.$route.query.id;
    this.search();
  },
  methods: {
    search() {
      const params = {
        memberId: this.memberId
      };
      searchIntegral(params).then(res => {
        if (res.status == 200) {
          if (!res.data.success) {
            return this.$message.error(ApiError.msg(res.data.message));
          }
          const data = res.data.data;
          this.tableData = data;
        }
      });
    },
    statusFormatter(row) {
      return Status[row.status]["name"];
    },
    datetimeFormatter(row) {
      return parseTime(row["createTime"]);
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/full-form";
@import "@/styles/common-table";
</style>
